package com.woniuxy.woniuhis.controller;

import javax.websocket.server.PathParam;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.woniuxy.woniuhis.annotation.SystemLog;
import com.woniuxy.woniuhis.entity.SurgeryExe;
import com.woniuxy.woniuhis.service.SurgeryExeService;
import com.woniuxy.woniuhis.util.ResponseJson;
import com.woniuxy.woniuhis.util.UUIDUtil;

@Controller
@RequestMapping("surgeryexe")
public class SurgeryExeController {
	
	@Autowired
	SurgeryExeService surgeryExeService;
	
	// 查询所有的执行记录
	@RequestMapping("/all")
	@ResponseBody
	// public ResponseJson<SurgeryExe> getAllSurgeryExes(@RequestBody SurgeryExe
	// surgeryExe,@RequestParam("page") Integer page,@RequestParam("limit") Integer
	// limit) {
	public ResponseJson<SurgeryExe> getAllSurgeryExes(@RequestBody SurgeryExe surgeryExe) {
		ResponseJson<SurgeryExe> responseJson = new ResponseJson<SurgeryExe>();
		try {
			System.out.println(surgeryExe);
			Integer page = surgeryExe.getPage();
			Integer limit = surgeryExe.getLimit();
			System.out.println("page:" + page + ",limit:" + limit);
			if (page == null) {
				page = 1;
			}
			if (limit == null) {
				limit = 10;
			}
			PageInfo<SurgeryExe> surgeryExes = surgeryExeService.findSurgeryExes(surgeryExe, page, limit);
			System.out.println(surgeryExes);
			responseJson.setCode(0);
			responseJson.setCount((int) surgeryExes.getTotal());
			responseJson.setData(surgeryExes.getList());
			return responseJson;
		} catch (Exception e) {
			responseJson.setCode(1);
			responseJson.setMsg(e.toString());
			e.printStackTrace();
			return responseJson;
		}
	}
	
	// 添加执行信息
	@RequestMapping("/add")
	@ResponseBody
	public ResponseJson addSurgeryExe(@RequestBody SurgeryExe surgeryExe) {
		ResponseJson responseJson = new ResponseJson();
		try {
			String uuid32 = UUIDUtil.uuid32();
			surgeryExe.setSurgeryExeId(uuid32);
			System.out.println(surgeryExe);
			surgeryExeService.addSurgeryExe(surgeryExe);
			responseJson.setCode(0);
			responseJson.setMsg("添加成功");
			return responseJson;
		} catch (Exception e) {
			responseJson.setCode(1);
			responseJson.setMsg(e.toString());
			e.printStackTrace();
			return responseJson;
		}
	}

	// 更新执行信息
	@RequestMapping("/update")
	@ResponseBody
	public ResponseJson updateSurgeryExe(@RequestBody SurgeryExe surgeryExe) {
		ResponseJson responseJson = new ResponseJson();
		try {
			surgeryExeService.modifySurgeryExe(surgeryExe);
			responseJson.setCode(0);
			responseJson.setMsg("修改成功");
			return responseJson;
		} catch (Exception e) {
			responseJson.setCode(1);
			responseJson.setMsg(e.toString());
			e.printStackTrace();
			return responseJson;
		}
	}
}
